package com.zjhd.sealcutting.controller;

import com.zjhd.sealcutting.domain.Area;
import com.zjhd.sealcutting.service.AreaService;
import com.zjhd.sealcutting.utils.response.ResponseResult;
import com.zjhd.sealcutting.utils.response.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * TODO
 *
 * @author wangchao
 * @version 1.0
 * @date 2020/11/20 14:19
 */
@Api(value = "地区服务", tags = "地区服务")
@RequestMapping("/area")
@RestController
public class AreaController {

    private final static Logger logger = LoggerFactory.getLogger(AreaController.class);

    @Autowired
    private AreaService areaService;

    @ApiOperation(value = "获取省市区接口", notes = "获取省市区接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId",value = "父地区ID",dataType = "Long" ,paramType = "query"),
            @ApiImplicitParam(name = "level",value = "层级",dataType = "Long" ,paramType = "query")
    })
    @GetMapping(value = "/queryParamArea")
    public ResponseResult<List<Area>> queryParamArea(Integer parentId, Integer level)throws Exception{
        try {
            return ResultGenerator.genSuccessResult(areaService.queryParamArea(parentId,level));
        }catch (Exception ex){
            logger.info("获取省市区接口处理异常："+ex,this.getClass());
        }
        return ResultGenerator.genFailResult("获取省市区信息失败");
    }
}
